package com.pandora.tv.view;

import com.pandora.tv.TabBrowserFragement;
import com.pandora.tv.TabEduFragement;
import com.pandora.tv.TabHomeFragement;
import com.pandora.tv.TabMediaFragement;
import com.pandora.tv.TabMyAppsFragement;
import com.pandora.tv.TabSettingFragement;
import com.pandora.tv.TabStoreFragement;
import com.pandora.tv.TabTvFragement;
import com.pandora.tv.TabVodFragement;
import com.pandora.tv.Utilities;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class TabPagerAdapter extends FragmentPagerAdapter{
	Context mContext;
	
	public TabPagerAdapter(Context con, FragmentManager fm) {
		super(fm);
		mContext = con;
	}

	@Override
    public Fragment getItem(int position) {
		Fragment result = null;
		switch (position) {
			case Utilities.TAB_HOME:
				result = new TabHomeFragement();
				break;
			case Utilities.TAB_TV:
				result = new TabTvFragement();
				break;
			case Utilities.TAB_VOD:
				result = new TabVodFragement();
				break;
			case Utilities.TAB_EDU:
				result = new TabEduFragement();
				break;
			case Utilities.TAB_MYAPPS:
				result = new TabMyAppsFragement();
				break;
			case Utilities.TAB_STORE:
				result = new TabStoreFragement();
				break;
			case Utilities.TAB_BROWSER:
				result = new TabBrowserFragement();
				break;
			case Utilities.TAB_MEDIA:
				result = new TabMediaFragement();
				break;
			case Utilities.TAB_SETTING:
				result = new TabSettingFragement();
				break;
		}
        return result;
    }
	
	
	@Override
	public CharSequence getPageTitle(int position) {
		// TODO Auto-generated method stub
		CharSequence result = null;
		switch (position) {
			case Utilities.TAB_HOME:
				result = "HOME";
				break;
			case Utilities.TAB_TV:
				result = "TV";
				break;
			case Utilities.TAB_VOD:
				result = "VOD";
				break;
			case Utilities.TAB_EDU:
				result = "EDU";
				break;
			case Utilities.TAB_MYAPPS:
				result = "MY APP";
				break;
			case Utilities.TAB_STORE:
				result = "PANDA STORE";
				break;
		}
		return result;
	}
	
	public Drawable getPageDrawable(int position) {
		Drawable result = null;
		switch (position) {
			case Utilities.TAB_BROWSER:
				result = mContext.getResources().getDrawable(android.R.drawable.ic_menu_mylocation);
				break;
			case Utilities.TAB_MEDIA:
				result = mContext.getResources().getDrawable(android.R.drawable.ic_menu_mylocation);
				break;
			case Utilities.TAB_SETTING:
				result = mContext.getResources().getDrawable(android.R.drawable.ic_menu_mylocation);
				break;
		}
		return result;
	}

	@Override
    public Object instantiateItem(ViewGroup container, int position) {
		int virtualPosition = position % getRealCount();
		return super.instantiateItem(container, virtualPosition);
    }

    @Override
	public void destroyItem(View container, int position, Object object) {
		// TODO Auto-generated method stub
    	int virtualPosition = position % getRealCount();
    	super.destroyItem(container, virtualPosition, object);
	}
	
	@Override
    public int getCount() {
    	return Integer.MAX_VALUE;
    }
	
	public int getRealCount() {
    	return Utilities.TAB_COUNT;
    }
	
	@Override
    public void destroyItem(ViewGroup container, int position, Object object) {
		int virtualPosition = position % getRealCount();
		super.destroyItem(container, virtualPosition, object);
    }
}
